<?php
namespace app\manager\controller;

class DriverType extends BaseController
{
    protected $check_auths = false; 
    /**
     * GET shwo drivertype info list
     * @return [type] [description]
     */
    public function index()
    {
        $list = model('DriverTypes')->getDriverTypesLists();
        $this->assign('list',$list);
        return view('p/drivertype/index');
    }

    /**
     * GET show drivertype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {
        
    }

    /**
     * GET shwo create drivertype info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('p/drivertype/create');
    }

    /**
     * POST create new drivertype info
     * @return [type] [description]
     */
    public function save()
    {
        
        $post_drivertype_info['name'] = input('post.name');
        $post_drivertype_info['profiles'] = input('post.profiles');
        
        $drivertype = model('DriverTypes')->createDriverType($post_drivertype_info);        
        if($drivertype){
            return $this->success(lang('create drivertype success'), '/drivertype');
        }
            return $this->error(lang('create drivertype failed').$drivertype['msg']);        
    }

    /**
     * GET edit drivertype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $data = model('DriverTypes')->getDriverTypeInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/drivertype/edit');
    }

    /**
     * PUT update drivertype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {
        $post_drivertype_info['name'] = input('post.name');
        $post_drivertype_info['profiles'] = input('post.profiles');
        
        $drivertype = model('DriverTypes')->updateDriverType($id, $post_drivertype_info);

        if($drivertype){
            return $this->success(lang('update drivertype success'), '/drivertype');
        }
            return $this->error(lang('update drivertype failed').$drivertype['msg']);
    }

    /**
     * DELETE drivertype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('DriverTypes')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/drivertype');
        }
        return $this->error('删除失败');
    }
}

